package com.suny.sf_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suny.DataDic.DataDic;
import org.springframework.stereotype.Service;
import com.suny.Farm.domain.Farm;
import com.suny.DataDicVal.DataDicVal;
import com.suny.sf_server.mapper.FarmMapper;
import com.suny.sf_server.mapper.DataDicValMapper;
import jakarta.annotation.Resource;

@Service
public class ValidationService {
    
    @Resource
    private FarmMapper farmMapper;
    
    @Resource
    private DataDicValMapper dataDicValMapper;
    
    /**
     * 检查字典值是否被引用
     */
    public boolean isDataDicValReferenced(Integer valId) {
        LambdaQueryWrapper<Farm> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Farm::getValId, valId);
        return farmMapper.selectCount(wrapper) > 0;
    }
    
    /**
     * 检查数据字典是否有值
     */
    public boolean hasDataDicVal(Integer dicId) {
        LambdaQueryWrapper<DataDicVal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DataDicVal::getDicId, dicId);
        return dataDicValMapper.selectCount(wrapper) > 0;
    }

    public Boolean hasDataDicValID(Integer valId) {
        LambdaQueryWrapper<DataDicVal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DataDicVal::getValId, valId);
        return dataDicValMapper.selectCount(wrapper) > 0;
    }
}